local waiwai = fk.CreateSkill {
  name = "lingling__waiwai",
  tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["lingling__waiwai"] = "歪歪",
  [":lingling__waiwai"] = "锁定技，你始终视为装备着【不正矛】。",
}

waiwai:addEffect(fk.PreCardUse, {
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(waiwai.name) and data.card.trueName == "slash" and #player:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and
      Fk.skills["#ling__inaccurate_spear_skill"] and Fk.skills["#ling__inaccurate_spear_skill"]:isEffectable(player)
  end,
  on_use = function(self, event, target, player, data)
    Fk.skills["#ling__inaccurate_spear_skill"]:use(event, target, player, data)
  end,
})

waiwai:addEffect(fk.Damage, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(waiwai.name) and
      data.card and data.card.trueName == "slash" then
      local e = player.room.logic:getCurrentEvent().parent
      while e do
        if e.event == GameEvent.UseCard then
          local use = e.data
          if use.extra_data and use.extra_data.inaccurate_spear and
            use.extra_data.inaccurate_spear.from == player and
            table.contains(use.extra_data.inaccurate_spear.new_tos, data.to.id) then
            event:setCostData(self, {tos = {data.to}, extra_data = use.extra_data.inaccurate_spear})
            return true
          end
        end
        e = e.parent
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    Fk.skills["##ling__inaccurate_spear_skill_2_trig"]:use(event, target, player, data)
  end,
})

waiwai:addEffect("atkrange", {
  correct_func = function(self, from, to)
    if from:hasSkill(waiwai.name) and #from:getAvailableEquipSlots(Card.SubtypeWeapon) > 0 and
      Fk.skills["#ling__inaccurate_spear_skill"] and Fk.skills["#ling__inaccurate_spear_skill"]:isEffectable(from) and
      from:getAttackRange(nil, {self.name}) < 2 then
      return 1
    end
  end,
})

waiwai:addAcquireEffect(function (self, player, is_start)
  player.room:addSkill("#ling__inaccurate_spear_skill")
end)

return waiwai
